package com.qf.fmall2203.alipay;
import com.github.wxpay.sdk.WXPay;
import java.util.HashMap;
import java.util.Map;

public class WxpayUtils {
    public static String getPayUrl(String orderId) throws Exception {
        //设置当前订单信息
        HashMap<String,String> data = new HashMap<>();
        data.put("body","testproduct");  //商品描述
        data.put("out_trade_no",orderId);               //使用当前用户订单的编号作为当前支付交易的交易号
        data.put("fee_type","CNY");                     //支付币种
        //data.put("total_fee",order.getActualAmount()*100+"");          //支付金额
        data.put("total_fee","1");
        data.put("trade_type","NATIVE");                //交易类型
        data.put("notify_url","http://47.118.45.73:8080/pay/callback");           //设置支付完成时的回调方法接口

        //发送请求，获取响应
        //微信支付：申请支付连接
        WXPay wxPay = new WXPay(new MyPayConfig());
        // 微信支付平台的统一下单接口
        Map<String, String> resp = wxPay.unifiedOrder(data);
        System.out.println(resp);
        return resp.get("code_url");
    }


    public static String queryOrder(String orderId) throws Exception {
        HashMap<String, String> params = new HashMap<>();
        params.put("out_trade_no", orderId);
        WXPay wxPay = new WXPay(new MyPayConfig());
        Map<String, String> resp = wxPay.orderQuery(params);
        System.out.println(resp);
        return resp.get("trade_state");
    }

    public static void main(String[] args) throws Exception {
        String orderId = "20221111092930123456789";  // 订单编号
        final String payUrl = getPayUrl(orderId);
        System.out.println(payUrl);
//        final String s = queryOrder(orderId);
//        System.out.println(s);
    }

}
